%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% File:               ReplicateTableA2.m
%
% Author:             Tasos Kalandrakis
%
% Description:        Script that replicates Table A2 by using previously 
% .                   computed test results                      
%
% Created:            Sep - 2021
%
% Last Modified:      Feb - 2022
%
% Language:           MATLAB
%
% Related References: [1] Kalandrakis, Tasos. 2022. "One-dimensional 
%                     scaling without apologies," Journal of Politics, 
%                     forthcoming.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filedir=pwd;

Surveys=strcat(filedir,'/CIRC/GERN.mat');
load(Surveys)

rdir=strcat(filedir,'/TESTRESULTS/');

Table4=cell(17,7);
TableA2=cell(23,8);

i=1;

TableA2{1,3}=1998;
TableA2{1,4}=2002;
TableA2{1,5}=2005;
TableA2{1,6}=2009;
TableA2{1,7}=2013;
TableA2{1,8}=2017;


TableA2{2,i}='Strong test';
TableA2{5,i}='Weak test';
TableA2{8,i}='Joint weak test';
TableA2{11,i}='J';
TableA2{12,i}='N';
TableA2{13,i}='Strong test';
TableA2{16,i}='Weak test';
TableA2{19,i}='Joint weak test';
TableA2{22,i}='J';
TableA2{23,i}='N';

i=i+1;

TableA2{2,i}='MAX';
TableA2{3,i}='QLR';
TableA2{4,i}='MMM';
TableA2{5,i}='MAX';
TableA2{6,i}='QLR';
TableA2{7,i}='MMM';
TableA2{8,i}='MAX';
TableA2{9,i}='QLR';
TableA2{10,i}='MMM';

TableA2{13,i}='MAX';
TableA2{14,i}='QLR';
TableA2{15,i}='MMM';
TableA2{16,i}='MAX';
TableA2{17,i}='QLR';
TableA2{18,i}='MMM';
TableA2{19,i}='MAX';
TableA2{20,i}='QLR';
TableA2{21,i}='MMM';


load(strcat(rdir,'M986v3.mat'))
TableA2{2,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'M98RU6v3.mat'))
TableA2{8,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M986v2.mat'))
TableA2{3,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M98RU6v2.mat'))
TableA2{9,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M986v1.mat'))
TableA2{4,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M98RU6v1.mat'))
TableA2{10,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M98Fv3.mat'))
TableA2{13,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'M98RUFv3.mat'))
TableA2{19,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M98Fv2.mat'))
TableA2{14,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M98RUFv2.mat'))
TableA2{20,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M98Fv1.mat'))
TableA2{15,i+1}=GERN.P98(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.P98(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M98RUFv1.mat'))
TableA2{21,i+1}=GERN.P98(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));


i=i+1;
load(strcat(rdir,'Ma026v3.mat'))
Table4{2,i}=GERN.Pa02(Est.Qorder);
Table4{3,i}=Est.Qsc;
Table4{4,i}=Est.Qsc/(nchoosek(Est.P,3)*Est.N);
Table4{5,i}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
Table4{6,i}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));
Table4{8,i}=Est.P;
Table4{9,i}=Est.N;

TableA2{2,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'Ma02RU6v3.mat'))
TableA2{8,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'Ma026v2.mat'))
TableA2{3,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'Ma02RU6v2.mat'))
TableA2{9,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'Ma026v1.mat'))
TableA2{4,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'Ma02RU6v1.mat'))
TableA2{10,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'Ma02Fv3.mat'))
TableA2{13,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'Ma02RUFv3.mat'))
TableA2{19,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'Ma02Fv2.mat'))
TableA2{14,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'Ma02RUFv2.mat'))
TableA2{20,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'Ma02Fv1.mat'))
TableA2{15,i+1}=GERN.Pa02(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.Pa02(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'Ma02RUFv1.mat'))
TableA2{21,i+1}=GERN.Pa02(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));




i=i+1;
load(strcat(rdir,'M056v3.mat'))
TableA2{2,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'M05RU6v3.mat'))
TableA2{8,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M056v2.mat'))
TableA2{3,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M05RU6v2.mat'))
TableA2{9,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M056v1.mat'))
TableA2{4,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M05RU6v1.mat'))
TableA2{10,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M05Fv3.mat'))
TableA2{13,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'M05RUFv3.mat'))
TableA2{19,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M05Fv2.mat'))
TableA2{14,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M05RUFv2.mat'))
TableA2{20,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M05Fv1.mat'))
TableA2{15,i+1}=GERN.P05(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.P05(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M05RUFv1.mat'))
TableA2{21,i+1}=GERN.P05(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));


i=i+1;
load(strcat(rdir,'M096v3.mat'))
TableA2{2,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'M09RU6v3.mat'))
TableA2{8,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M096v2.mat'))
TableA2{3,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M09RU6v2.mat'))
TableA2{9,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M096v1.mat'))
TableA2{4,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M09RU6v1.mat'))
TableA2{10,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M09Fv3.mat'))
TableA2{13,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'M09RUFv3.mat'))
TableA2{19,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M09Fv2.mat'))
TableA2{14,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M09RUFv2.mat'))
TableA2{20,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M09Fv1.mat'))
TableA2{15,i+1}=GERN.P09(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.P09(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M09RUFv1.mat'))
TableA2{21,i+1}=GERN.P09(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));


i=i+1;
load(strcat(rdir,'M136v3.mat'))
TableA2{2,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'M13RU6v3.mat'))
TableA2{8,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M136v2.mat'))
TableA2{3,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M13RU6v2.mat'))
TableA2{9,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M136v1.mat'))
TableA2{4,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M13RU6v1.mat'))
TableA2{10,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M13Fv3.mat'))
TableA2{13,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'M13RUFv3.mat'))
TableA2{19,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M13Fv2.mat'))
TableA2{14,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M13RUFv2.mat'))
TableA2{20,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M13Fv1.mat'))
TableA2{15,i+1}=GERN.P13(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.P13(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M13RUFv1.mat'))
TableA2{21,i+1}=GERN.P13(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));


i=i+1;
load(strcat(rdir,'M176v3.mat'))
TableA2{2,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{5,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

TableA2{11,i+1}=Est.P;
TableA2{12,i+1}=Est.N;

load(strcat(rdir,'M17RU6v3.mat'))
TableA2{8,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M176v2.mat'))
TableA2{3,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{6,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M17RU6v2.mat'))
TableA2{9,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M176v1.mat'))
TableA2{4,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{7,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M17RU6v1.mat'))
TableA2{10,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{11,i+1},:));

load(strcat(rdir,'M17Fv3.mat'))
TableA2{13,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{16,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

TableA2{22,i+1}=Est.P;
TableA2{23,i+1}=Est.N;

load(strcat(rdir,'M17RUFv3.mat'))
TableA2{19,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M17Fv2.mat'))
TableA2{14,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{17,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M17RUFv2.mat'))
TableA2{20,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));

load(strcat(rdir,'M17Fv1.mat'))
TableA2{15,i+1}=GERN.P17(Est.Orders(Est.rejectB==0,:));
TableA2{18,i+1}=GERN.P17(Est.Orders(Est.rejectR==0,:));

load(strcat(rdir,'M17RUFv1.mat'))
TableA2{21,i+1}=GERN.P17(Est.Orders(sum(Est.reject,2)<TableA2{22,i+1},:));


openvar('Table4')
openvar('TableA2')